\documentclass{report}
\usepackage[UTF8]{ctex}
\usepackage{amsthm,amsmath,amssymb}
\usepackage{mathrsfs} %导入花体数学字母
\usepackage{caption}
\usepackage{graphicx, subfig} %插入图片
\usepackage{listings} %插入代码
\usepackage{xcolor} %语法高亮
\usepackage{fontspec} %字体包
\usepackage{diagbox} % 斜线表头
\usepackage{geometry} %设置页面
\usepackage{enumerate}
\usepackage[colorlinks,linkcolor=blue]{hyperref} %超链接
\usepackage{marginnote} % 在正文旁边添加注释文字

\setlength{\marginparwidth}{0.6in} %页边空白处设定宽度0.6英寸
\let\oldmarginpar\marginpar
\renewcommand\marginpar[1]{\-\oldmarginpar[\raggedleft\footnotesize\color{red} #1]%
	{\raggedright\footnotesize\color{red} #1}} % 注释文字用红色footnote 大小
\marginparsep = 10pt %与正文间隔10pt

% \marginpar{需要添加的内容}
% 显示或隐藏页边注释，只要在文件头添加下面的语句，把它注释掉后又显示页边内容
% \renewcommand{\marginpar}[2][]{}

\geometry{a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm}

\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\arabic{section}.\ #1}}
\lhead[\thepage]{\leftmark} 
\rhead[\nouppercase{\rightmark}]{\thepage}

\lstset{
	columns=fixed,       
	numbers=left,                                        % 在左侧显示行号
	numberstyle=\color{black},                       % 设定行号格式
	basicstyle=\fontspec{Consolas}\small\color[RGB]{212,212,212},
	tabsize=4,
	frame=single,                                        % 背景边框
	rulecolor=\color[rgb]{0,0,0},                  % 边框颜色
	extendedchars=false,                                 % 解决换页问题
	backgroundcolor=\color[RGB]{30,30,30},            % 设定背景颜色
	keywordstyle=\color[RGB]{156,220,254},                 % 设定关键字颜色
	identifierstyle=\color[RGB]{86,156,214},                       % 普通标识符颜色
	commentstyle=\it\color[RGB]{106,153,73},                % 设置代码注释的格式
	stringstyle=\rmfamily\slshape\color[RGB]{206,145,91},   % 设置字符串格式
	showstringspaces=false,                              % 不显示字符串中的空格
	language=c++,                                        % 设置语言
	escapeinside=``,                                     % 逃逸字符
	xleftmargin=1em,                                     % 边距设置
	xrightmargin=1em, 
	aboveskip=1em
}

\title{{\Huge Homework5\\ 数值分析}}
\author{{\LARGE 3190105815 信息与计算科学\ 行一凡}}
\date{{\LARGE \today}}

\begin{document}
	\maketitle
	\section*{Exercise I}
	先证$ L_{\rho}^{2}[a,b] = \{f(x)\in L[a,b]:\rho(x)|f(x)|^{2}\in L[a,b]\} $为向量空间
	\begin{itemize}
		\item $ \forall f,g\in L_{\rho}^{2}[a,b] $
		\begin{equation}\label{key}
			\begin{aligned}
				\int_{a}^{b}\left|\rho(t)|f(t)+g(t)|^{2}\right|dt &\le 2\int_{a}^{b}|\rho(t)|[f^{2}(t) + g^{2}(t)]dt\\ 
				&= \int_{a}^{b}|\rho(t)|f^{2}(t)dt + \int_{a}^{b}|\rho(t)|g^{2}(t)dt\\ 
				&<+\infty
			\end{aligned}
		\end{equation}
		从而$ f+g\in L_{\rho}^{2}[a,b] $；显然，$ L_{\rho}^{2}[a,b] $关于数乘封闭，且有加法交换律和结合律
		
		\item 常函数$ f(x) = 0 \in L_{\rho}^{2}[a,b] $，则同理由定积分性质，$ \forall g\in L_{\rho}^{2}[a,b],\ f+g = g\in L_{\rho}^{2}[a,b] $，即$ f $为零元
		
		\item $ \forall f\in L_{\rho}^{2}[a,b],\ 1f = f\in L_{\rho}^{2}[a,b] $
		
		\item $ \forall f\in L_{\rho}^{2}[a,b] $，有
		\begin{equation}\label{key}
			\int_{a}^{b}\left|\rho(t)|-f(t)|^{2}\right|dt = \int_{a}^{b}\left|\rho(t)|f(t)|^{2}\right|dt <+\infty
		\end{equation}
		故$ -f\in L_{\rho}^{2}[a,b] $，存在逆元
		
		\item 对$ \forall c_1,c_2\in \mathbb{R},\ \forall f,g\in L_{\rho}^{2}[a,b],\ (c_1+c_2)f = c_1f+c_2f,\ c_1(f+g) = c_1f+c_1g,\ c_1(c_2f) = (c_1c_2)f $
	\end{itemize}
	再证$ \rho(x) > 0 $时，$ L_{\rho}^{2}[a,b] $为$ \mathbb{R} $上的内积空间，内积定义为
	\begin{equation}\label{key}
		\left<u,v\right> = \int_{a}^{b}\rho(t)u(t)\overline{v(t)}dt
	\end{equation}
	\begin{itemize}
		\item $ \forall u\in L_{\rho}^{2}[a,b] $
		\begin{equation}\label{key}
			\left<u,u\right> = \int_{a}^{b}\rho(t)u^{2}(t)dt \ge 0
		\end{equation}
		由被积函数的非负性，$ \left<u,u\right> = 0 \Leftrightarrow u = 0 $
		
		\item $ \forall u,v\in L_{\rho}^{2}[a,b] $
		\begin{equation}\label{key}
			\begin{aligned}
				\left<u,v\right> &= \int_{a}^{b}\rho(t)u(t)\overline{v(t)}dt\\
				&= \overline{\int_{a}^{b}\rho(t)v(t)\overline{u(t)}dt}\\ 
				&= \overline{\left<v,u\right>}
			\end{aligned}
		\end{equation}
	
		\item $ \forall u,v,w\in L_{\rho}^{2}[a,b] $
		\begin{equation}\label{key}
			\begin{aligned}
				\left<u+v,w\right> &= \int_{a}^{b}\rho(t)[u(t)+v(t)]\overline{w(t)}dt\\
				&= \int_{a}^{b}\rho(t)u(t)\overline{w(t)}dt + \int_{a}^{b}\rho(t)v(t)\overline{w(t)}dt\\ 
				&= \left<u,w\right> + \left<v,w\right>
			\end{aligned}
		\end{equation}
	
		\item $ \forall c\in\mathbb{R},\forall u,v\in L_{\rho}^{2}[a,b] $
		\begin{equation}\label{key}
			\begin{aligned}
				\left<cu,v\right> &= \int_{a}^{b}\rho(t)cu(t)\overline{v(t)}dt\\
				&= c\int_{a}^{b}\rho(t)u(t)\overline{v(t)}dt\\ 
				&= c\left<u,v\right>
			\end{aligned}
		\end{equation}
	\end{itemize}
	最后，由2范数的定义，有
	\begin{equation}\label{key}
		\begin{aligned}
			\| u\|_2 &= \sqrt{\left<u,u\right>}\\ 
			&= \left(\int_{a}^{b}\rho(t)|u(t)|^{2}dt\right)^{\frac{1}{2}}
		\end{aligned}
	\end{equation}

	\section*{Exercise II}
	\begin{enumerate}[(a)]
		\item 先计算前两项 Chebyshev 多项式
		\begin{equation}\label{key}
			u_1 = v_1 = 1,\ u_{1}^{*} = \dfrac{v_{1}}{\| v_{1}\|} = \dfrac{1}{\sqrt{\pi}}
		\end{equation}
		\begin{equation}\label{key}
			v_{2} = x - \dfrac{1}{\sqrt{\pi}}\int_{-1}^{1}\dfrac{1}{\sqrt{1-x^{2}}}\cdot x\dfrac{1}{\sqrt{\pi}}dx = x
		\end{equation}
		\begin{equation}\label{key}
			u_{2}^{*} = \dfrac{v_{2}}{\| v_{2}\|} = \sqrt{\dfrac{2}{\pi}}x
		\end{equation}
		\begin{equation}\label{key}
			\left<u_{1}^{*},u_{2}^{*}\right> = \dfrac{\sqrt{2}}{\pi}\int_{-1}^{1}\dfrac{x}{\sqrt{1-x^{2}}}dx = 0
		\end{equation}
		不妨设前$ n $项满足标准正交关系，则有
		\begin{equation}\label{key}
			v_{n+1} = u_{n+1} - \sum_{k=1}^{n}\left<u_{n+1},u_{k}^{*}\right>u_{k}^{*}
		\end{equation}
		\begin{equation}\label{key}
			\begin{aligned}
				\left<v_{n+1},u_{j}^{*}\right> &= \left<u_{n+1},u_{j}^{*}\right> - \sum_{k=1}^{n}\left<u_{n+1},u_{k}^{*}\right>\left<u_{k}^{*},u_{j}^{*}\right>\\ 
				&= \left<u_{n+1},u_{j}^{*}\right> - \left<u_{n+1},u_{j}^{*}\right>\left<u_{j}^{*},u_{j}^{*}\right>\\ 
				&= 0
			\end{aligned}
		\end{equation}
		从而显然有
		\begin{equation}\label{key}
			\left<u_{n+1}^{*},u_{j}^{*}\right> = 0,\ \left<u_{n+1}^{*},u_{n+1}^{*}\right> = 1
		\end{equation}
		由归纳法即证。
		
		\item 由 (a) 可得
		\begin{equation}\label{key}
				v_3 = x^2 - u_{1}^{*}\int_{-1}^{1}\dfrac{x^2}{\sqrt{1-x^{2}}}\cdot u_{1}^{*}dx - u_{2}^{*}\int_{-1}^{1}\dfrac{x^2}{\sqrt{1-x^{2}}}\cdot u_{2}^{*}dx = x^{2} - \dfrac{1}{2}
		\end{equation}
		从而有
		\begin{equation}\label{key}
			\begin{aligned}
				u_{1}^{*} &= \dfrac{1}{\sqrt{\pi}}\\ 
				u_{2}^{*} &= \sqrt{\dfrac{2}{\pi}}x\\ 
				u_{3}^{*} &= \sqrt{\dfrac{8}{\pi}}(x^2-\dfrac{1}{2})
			\end{aligned}
		\end{equation}
	\end{enumerate}

	\section*{Exercise III}
	\begin{enumerate}[(a)]
		\item Chebyshev 多项式如上题所得
		\begin{equation}\label{key}
			\begin{aligned}
				\left<y,u_{1}^{*}\right> &= \int_{-1}^{1}\dfrac{1}{\sqrt{1-x^2}}\cdot \sqrt{1-x^2}\cdot \dfrac{1}{\sqrt{\pi}}dx = \dfrac{2}{\sqrt{\pi}}\\ 
				\left<y,u_{2}^{*}\right> &= \int_{-1}^{1}\dfrac{1}{\sqrt{1-x^2}}\cdot \sqrt{1-x^2}\cdot \dfrac{2}{\sqrt{\pi}}xdx = 0\\ 
				\left<y,u_{3}^{*}\right> &= \int_{-1}^{1}\dfrac{1}{\sqrt{1-x^2}}\cdot \sqrt{1-x^2}\cdot \sqrt{\dfrac{8}{\pi}}(x^2-\dfrac{1}{2})dx = -\sqrt{\dfrac{8}{9\pi}}
			\end{aligned}
		\end{equation}
		从而有二次近似多项式
		\begin{equation}\label{key}
			\phi(x) = - \dfrac{8}{3\pi}x^2 + \dfrac{10}{3\pi}
		\end{equation}
	
		\item 由内积定义有
		\begin{equation}\label{key}
			G(1,x,x^2) = \left[
				\begin{matrix}
					\left<1,1\right> & \left<1,x\right> & \left<1,x^2\right>\\ 
					\left<x,1\right> & \left<x,x\right> & \left<x,x^2\right>\\ 
					\left<x^2,1\right> & \left<x^2,x\right> & \left<x^2,x^2\right>
				\end{matrix}
			\right] = \left[
				\begin{matrix}
					\pi & 0 & \frac{\pi}{2}\\ 
					0 & \frac{\pi}{2} & 0\\ 
					\frac{\pi}{2} & 0 & \frac{3\pi}{8}
				\end{matrix}
			\right]
		\end{equation}
		计算向量
		\begin{equation}\label{key}
			\mathbf{c} = \left[
				\begin{matrix}
					\left<y,1\right>\\ 
					\left<y,x\right>\\ 
					\left<y,x^2\right>
				\end{matrix}
			\right] = \left[
				\begin{matrix}
					2\\ 
					0\\ 
					\frac{2}{3}
				\end{matrix}
			\right]
		\end{equation}
		解得系数为
		\begin{equation}\label{key}
			a_0 = \dfrac{10}{3\pi},\ a_1 = 0,\ a_2 = -\dfrac{8}{3\pi}
		\end{equation}
		从而有二次近似多项式
		\begin{equation}\label{key}
			\phi(x) = - \dfrac{8}{3\pi}x^2 + \dfrac{10}{3\pi}
		\end{equation}
	\end{enumerate}

	\section*{Exercise IV}
	\begin{enumerate}[(a)]
		\item 
		\begin{equation}\label{key}
			v_1 = u_1 = 1,\ u_{1}^{*} = \dfrac{v_{1}}{\| v_{1}\|} = \dfrac{1}{\sqrt{12}}
		\end{equation}
		\begin{equation}\label{key}
			v_2 = x - \dfrac{1}{\sqrt{12}}\sum_{i=1}^{12}\dfrac{1}{\sqrt{12}}x_i = x - \dfrac{13}{2}
		\end{equation}
		\begin{equation}\label{key}
			u_{2}^{*} = \dfrac{v_{2}}{\| v_{2}\|} = \dfrac{2x - 13}{2\sqrt{143}}
		\end{equation}
		\begin{equation}\label{key}
			\begin{aligned}
				v_3 &= x^2 - \dfrac{1}{\sqrt{12}}\sum_{i=1}^{12}x_{i}^{2}\cdot \dfrac{1}{\sqrt{12}} - \dfrac{2x - 13}{2\sqrt{143}}\sum_{i=1}^{12}x_{i}^{2}\cdot \dfrac{2x_i - 13}{2\sqrt{143}}\\ 
				&= x^2 - 13x + \dfrac{91}{3}
			\end{aligned}
		\end{equation}
		\begin{equation}\label{key}
			u_{3}^{*} = \dfrac{v_{3}}{\| v_{3}\|} = \sqrt{\dfrac{3}{4004}}\left(x^2 - 13x + \dfrac{91}{3}\right)
		\end{equation}
	
		\item 利用内积计算在不同分量系数
		\begin{equation}\label{key}
			\left<y,u_{1}^{*}\right> = \sum_{i=1}^{12}\dfrac{1}{\sqrt{12}}y_i = \dfrac{1662}{\sqrt{12}}
		\end{equation}
		\begin{equation}\label{key}
			\left<y,u_{2}^{*}\right> = \sum_{i=1}^{12}\dfrac{2x_i - 13}{2\sqrt{143}}y_i = \dfrac{589}{\sqrt{143}}
		\end{equation}
		\begin{equation}\label{key}
			\left<y,u_{3}^{*}\right> = \sum_{i=1}^{12}\sqrt{\dfrac{3}{4004}}\left(x_i^2 - 13x_i + \dfrac{91}{3}\right)y_i = 12068\sqrt{\dfrac{3}{4004}}
		\end{equation}
		从而有近似多项式
		\begin{equation}\label{key}
			\begin{aligned}
				\phi(x) &= \dfrac{1662}{12} + \dfrac{589}{143}\left(x-\dfrac{13}{2}\right) + \dfrac{12068\times 3}{4004}\left(x^2-13x+\dfrac{91}{3}\right)\\ 
				&\approx 9.04x^2 - 113.43x + 386
			\end{aligned}
		\end{equation}
		与讲义中的结果相同，即证。
		
		\item 由于作为点自变量的横坐标$ x_i $和点的数量$ N $都不改变，因此上面对正交多项式的计算结果可以保留，而近似多项式计算的分量系数$ a_i = \left<y,u_{i}^{*}\right> $需要重新计算。\\ 
		对于在相同自变量的情况下多次计算得到的数据，这种对自变量$ x_i $的重用可以节省每次近似的计算时间，提高运行效率。
	\end{enumerate}

	\section*{Code A}
	计算结果为$ a = (2.17572,2.67041,-0.238444) $，从而有近似多项式
	\begin{equation}\label{key}
		\phi(x) = 2.17572 + 2.67041x - 0.238444x^{2}
	\end{equation}

	\section*{Code B}
	计算结果同样为$ a = (2.17572,2.67041,-0.238444) $，正交多项式矩阵$ G $有条件数
	\begin{equation}\label{key}
		\Vert G\Vert_2\Vert G^{-1}\Vert_2 = 18980.9
	\end{equation}
	最小二乘矩阵$ A $得到的分解$ R_1 $有条件数
	\begin{equation}\label{key}
		\Vert R_1\Vert_2\Vert R_1^{-1}\Vert_2 = 137.771
	\end{equation}
	因此最小二乘法得到的矩阵条件数远小于前者。
	
\end{document}